package Tree;

import javax.swing.tree.TreeNode;
import java.util.LinkedList;
import java.util.List;

public class p144二叉树的前序遍历 {
    class Solution {
        LinkedList<Integer> list = new LinkedList<>();
        List<Integer> res = new LinkedList<>();
        public List<Integer> preorderTraversal(TreeNode root) {
            list.push(root);
            while(!list.isEmpty()){
                res.add(list.pop());
                if(root.right != null) list.push(root.right);
                if(root.left != null) list.push(root.left);
            }
            return res;
        }
    }
}
